*******************************************************************************
* PlaySound.init.aii
*
* (C)  Copyright Apple Computer, Inc. 1988
* All rights reserved.
*
* by Jim Mensch & Keith Rollin
* 7/11/88
*
* This file contains standard routines used by all the applications on the DTS
* Demo Disk. This file relies on certain data structures being available in a GLOBALS
* data record in the main file. This file has been modified to not create menus
* and to start up standard file and the sound tools.
*
* Files:        System macros and equates
*
*
*
* Modification History:
*
* Version 1.0   Jim Mensch and Keith Rollin
*
*      7/11/88  Initial Release
*
* Version 1.1   Jim Mensch
*
*       7/12/88 Modified to include standard file and sound startups
*
*               
*
*******************************************************************************

                EJECT
*******************************************************************************
*
InitTools       start
*
* Description:  Load and initialize the tools needed. Errors are detected
*               and FatalError is called if any occur. If there aren't any
*               errors, the list of menu templates is read and the menu-
*               bar is created.
*
*
* Inputs:       NONE
*
* Outputs:      NONE
*
* External Refs:
*               Import FatalError
*
* Entry Points: NONE
*
*******************************************************************************
                using Globals

;
;   Tool Direct page offsets here
;
QDDPage         equ $0000
EMDPage         equ QDDPage+$0300
CtlDPage        equ EMDPage+$0100
MenuDPage       equ CtlDPage+$0100
LEDPage         equ MenuDPage+$0100
SFDPage         equ LEDPage+$0100
SoundDPage      equ SFDPage+$0100
ToolDPSize      equ SoundDPage+$0100

                phk             ; Save program bank register and
                plb             ; load it as the data bank register

                tdc
                sta MyDP        ; Save direct register

                _TLStartup      ; Start Tool Locator

                pha             ; Space for result
                _MMStartup      ; Start memory manager
                PullWord MyID   ; Save it for later use

                _MTStartup      ; Start up Misc Tools

                _IMStartup      ; Start integer math toolset

                PushLong #ToolTable             ; Pointer to Tool table
                _LoadTools      ; Load all RAM based tools
                bcc IT0005      ; Carry clear means no error
                brl FatalError  ; Tools can't be loaded. Fatal error!

IT0005          ANOP

; Get memory for Tool Direct pages

                pha             ; Room for result
                pha
                PushLong #ToolDPSize ; Number of bytes needed
                PushWord MyID   ; ID of this application
                PushWord #AttrLocked+attrFixed+attrPage+attrBank
                PushLong #0     ; Allocate them in bank 0
                _NewHandle
                bcc IT0010      ; Test carry for error
                brl FatalError  ; If no memory we got a fatal error!

IT0010          PullLong DPHandle               ; Retrieve handle to our DPage area

                lda [DPHandle]  ; Dereference the handle to get a ptr
                sta DPPointer   ; to our direct page area and save it.

                PushWord DPPointer              ; QuickDraw uses 3 pages of Dpage
                PushWord #ScreenMode ; Used to set all master SCB's
                PushWord #0     ; Zero means use default buf size
                PushWord MyID   ; Application ID for allocating data
                _QDStartup      ; Start QuickDraw, turn on SHR Screen
                bcc IT0015
                brl FatalError  ; If it can't be started then bomb

IT0015          ANOP
                lda DPPointer   ; Create address for Event Mgr DPage by
                clc             ; loading in the pointer to the start
                adc #EMDPage    ; of DPage and adding Evt Mgr offset.
                pha             ; Now push it on the stack.
                PushWord #20    ; Size of event queue.
                PushWord #0     ; MouseClamp values.
                PushWord #ScreenWidth ; These will clamp mouse to screen
                PushWord #0     ; area only.
                PushWord #200
                PushWord MyID
                _EMStartup      ; Start the event manager
                bcc IT0020
                brl FatalError  ; Event manager is also a must
IT0020          ANOP
                PushWord MyID
                _WindStartup
                bcc IT0025
                brl FatalError
IT0025          ANOP
                PushWord MyID
                lda DPPointer
                clc
                adc #CtlDPage
                pha
                _CtlStartup
                bcc IT0030
                brl FatalError
IT0030          ANOP

                PushWord MyID
                lda DPPointer
                clc
                adc #MenuDPage
                pha
                _MenuStartUp
                bcc IT0035
                brl FatalError
IT0035          ANOP
                PushWord MyID
                lda DPPointer
                clc
                adc #LEDPage
                pha
                _LEStartUp
                bcc IT0040
                brl FatalError
IT0040          ANOP
                PushWord MyID
                _DialogStartup
                bcc IT0045
                brl FatalError
IT0045          ANOP
                PushWord MyID
                lda DPPointer
                clc
                adc #SFDPage
                pha
                _SFStartUp
                bcc IT0050
                brl FatalError
IT0050          ANOP
                lda DPPointer
                clc
                adc #SoundDPage
                pha
                _SoundStartup
                bcc IT0055
                brl FatalError
IT0055          ANOP
                _ScrapStartup   ; No errors possible for this call

                _DeskStartup    ; No error possible for this call

                PushLong #0
                _RefreshDeskTop


                RTS

ToolTable       dc i2'7'        ; Data Block for LoadTools call
                dc i2'14,$0100' ; Window Manager
                dc i2'15,$0100' ; Menu Manager
                dc i2'16,$0100' ; Control Manager
                dc i2'20,$0100' ; LineEdit tool set
                dc i2'21,$0100' ; Dialog Manager
                dc i2'22,$0100' ; Scrap manager
                dc i2'23,$0100' ; standard file

                end

                EJECT
*******************************************************************************
*
FatalError      start
*
* Description:  Routine that is called whenever a tool sends back an error
*               that can not be recovered from. This routine prints the
*               error on the screen, waits for a keypress then quits back
*               to whoever started this application up!
*
*
* Inputs:       A = Error number
*
* Outputs:      NONE (program exits)
*
* External Refs:
*               Import CloseTools
*
* Entry Points: NONE
*
*******************************************************************************
                using Globals

                pha             ; Push the error code
                PushLong #errNumStr             ; Address of storage area
                PushWord #4     ; Length of string
                _Int2Hex

                _GrafOff        ; If QD Started, shut off graphics

                PushLong #ErrStr                ; Write error message to the screen
                _WriteCString

                pha             ; Space for result
                PushWord #0     ; No echo
                _ReadChar       ; Wait for a key to be pressed
                pla             ; Discard the key

                jsr CloseTools  ; Shut down all the tools in case
;                                 any got started up

                _Quit QuitParms ; Quit back to where we came from.

                brk $FF         ; If the quit fails then just break
                
ErrStr          dc c'A fatal error has occured $'
ErrNumStr       dc c'xxxx   press any key to exit',i1'0'

                end

                EJECT
*******************************************************************************
*
CloseTools      start
*
* Description:  Shut down the tools I started.
*
*
* Inputs:       NONE
*
* Outputs:      NONE
*
* External Refs:                NONE
*
* Entry Points: NONE
*
*******************************************************************************
                using Globals

                _DeskShutDown
                _ScrapShutDown
                _SoundShutDown
                _DialogShutDown
                _LEShutDown
                _MenuShutDown
                _CtlShutDown
                _WindShutDown
                _EMShutDown
                _QDShutDown
                _MTShutDown

                PushLong DPHandle               ; Dispose of all that DP memory
                _DisposeHandle

                PushWord MyID
                _MMShutDown
                _TLShutDown

                rts
                end

                EJECT
*******************************************************************************
*
doAbout         start
*
* Description:  Bring up an Alert Dialog box with our name in it.
*
* Inputs:       NONE
*
* Outputs:      NONE
*
* External Refs:                NONE
*
* Entry Points: NONE
*
*******************************************************************************
                using Globals

                pha             ; space for result
                PushLong #AboutBox              ; pointer to alert template
                PushLong #0     ; pointer to a filter proc (0=none)
                _NoteAlert
                pla             ; get the item hit and dispose

                rts

; About Box alert template

AboutBox        dc i2'30,30,100,590'            ; for 320 use 30,30,100,290
                dc i2'1'        ; this is alert # 1
                dc i1'$80'      ; draw for this stage
                dc i1'$81'      ; draw for this stage
                dc i1'$82'      ; draw for this stage
                dc i1'$83'      ; draw for this stage
                dc i4'OkButton' ; ok button for the             alert
                dc i4'AboutTitle'               ; title of the program
                dc i4'AboutAut' ; author
                dc i4'AboutVers'                ; version number string
                dc i4'0'        ; nil to end the list

OKBTitle        str 'OK'
OKButton        dc i2'1'
                dc i2'50,500,65,550'
                dc i2'ButtonItem'
                dc i4'OKBTitle'
                dc i2'0'
                dc i2'0'        ; item flag
                dc i4'0'        ; no color table

AboutTitle      dc i2'2'
                dc i2'10,100,20,550'
                dc i2'StatText+ItemDisable'
                dc i4'TitleString'
                dc i2'0'
                dc i2'0'        ; item flag
                dc i4'0'        ; no color table

AboutAut        dc i2'3'
                dc i2'25,100,35,550'
                dc i2'StatText+ItemDisable'
                dc i4'AutString'
                dc i2'0'
                dc i2'0'        ; item flag
                dc i4'0'        ; no color table

AboutVers       dc i2'4'
                dc i2'40,100,50,550'
                dc i2'StatText+ItemDisable'
                dc i4'VersString'
                dc i2'0'
                dc i2'0'        ; item flag
                dc i4'0'        ; no color table

                end
